﻿<!DOCTYPE html>
<html>
	<head>
		<meta charset="gb2312">
		<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0,user-scalable=no" id="viewport">
		<title>密码找回-迅泊达</title>
		<link rel="shortcut icon" href="favicon.ico"/>
		<link rel="stylesheet" href="css/base.css" />
		<link rel="stylesheet" href="css/find-password-phone.css" />
		<link rel="stylesheet" href="font/fanhui/iconfont.css" />
		<script src='js/jquery-1.11.2.min.js'></script>
		<script src="js/xbddai.js"></script>
		<script src="js/base.js"></script>
		<script src="js/51size.js"></script>
	</head>
	<body>
		<header class="clearfix">
			<div class="header clearfix">
				<ul>
					<li>
						<a href="login.html">
							<i class="iconfont left-icon">&#xe64c;</i>
							<em>返回</em>
						</a>
					</li>
					<li>密码找回</li>
					<li></li>
				</ul>
			</div>
		</header>
		<!--头部结束-->
		
		 <!--主体   开始-->
		 <main>
		 	<div class="register clearfix">
		 		<div class="register-user clearfix">
					<span class="phone current" style="width:100%;">通过手机找回</span>
					<!--<span class="mell">通过邮箱找回</span>-->
		 		</div>
				<dl class=" find-main">
					<dd class="find-current find-show">
						<div class="register-information clearfix">
							<ul>
								<li>
									<div>手机号</div>
									<div>
										<input type="text" placeholder="请输入手机号" id="phone"/>
									</div>
								</li>
								<li>
									<div>验证码</div>
									<div>
										<input type="text" placeholder="请输入您收到的验证码" id="code"/>
									</div>
									<span class="msgs" id="getCode">获取短信验证码</span>
								</li>
								<li>
									<div>密码</div>
									<div>
										<input type="password" placeholder="请设置新密码（6-20个字符）" id="pwd"/>
									</div>
								</li>
								<li>
									<div>确认密码</div>
									<div>
										<input type="password" placeholder="请再次输入新密码" id="qrpwd"/>
									</div>
								</li>
							</ul>
						</div>
						<div class="register-footer">
							<div class="register-btn">
								<input type="button" value="提交信息" id="submit"/>
							</div>
						</div>
					</dd>
					<!--<dd class=" find-show">
						<div class="register-information clearfix">
							<ul>
								<li>
									<div>邮箱</div>
									<div>
										<input type="text" placeholder="请输入邮箱"/>
									</div>
								</li>
								<li class="code">
									<div>验证码</div>
									<div class="code-in">
										<input type="text" placeholder="请输入您收到的验证码"/>
										<span class="msgs">获取短信验证码</span>
									</div>
								</li>
								<li>
									<div>密码</div>
									<div>
										<input type="password" placeholder="请设置密码(6-20个字符)"/>
									</div>
								</li>
								<li>
									<div>确认密码</div>
									<div>
										<input type="password" placeholder="请再次输入密码"/>
									</div>
								</li>
							</ul>
						</div>
						<div class="register-footer">
							<div class="register-btn">
								<input type="submit" value="提交信息" />
							</div>
						</div>
					</dd>-->
				</dl>
		 	</div>
		 </main>
		 <!--主体   结束-->
	</body>
<script>
	$(function(){
		$("#submit").click(function(event) {
			var phone = $("#phone").val();
			var code = $("#code").val();
			var pwd = $("#pwd").val();
			var qrpwd = $("#qrpwd").val();
			var reg = /^(((1[0-9][0-9]{1})|159|153)+\d{8})$/;
			if (!reg.test(phone)) {
				alert("请正确填入手机号!");
				return false;
			}
			if (code =='') {
				alert("请输入验证码!");
				return false;
			}
			if (pwd != qrpwd) {
				alert("两次输入的新密码不一致!");
				return false;
			}
			var randomCode = localStorage.getItem('randomCode');
			var info = {
				phone: phone,
				password: pwd,
				code: code,
				randomCode: randomCode
			};
			console.log(info);
			$.ajax({
				type: 'post',
				dataType: 'JSON',
				async: false,
				url: baseUrl + "/app/pwd/update",
				data:info,
				success: function(result) {
					var msg = result["msg"];
					var code = result["code"];
					//console.log(result);
					if (code == '-1') {
						alert('操作成功,请重新登录！！！');
						localStorage.removeItem('randomCode');
						//window_href('pwd_success.html')
						window.location.href="login.html";
					} else {
						alert(msg);
					}
				}
			});
			event.stopPropagation();
		})
		/*    获取验证码*/
		$("#getCode").click(function(event) {
			if ($(this).hasClass('msgs1')) {
				return false;
			}
			var phone = $("#phone").val();
			var reg = /^(((1[0-9][0-9]{1})|159|153)+\d{8})$/;
			if (!reg.test(phone)) {
				alert("请正确填入手机号!");
				return false;
			}
			$.ajax({
				type: 'post',
				dataType: 'JSON',
				async: false,
				url: baseUrl + "/app/send",
				data: {
					phone: phone
				},
				success: function(result) {
					var code = result["code"];
					if (code == '-1') {
						localStorage.setItem('randomCode', result['entity']["randomCode"]);
						timedCount();
						alert('获取验证码成功!');
					} else {
						alert(result["msg"]);
					}
					event.stopPropagation();
				}
			});
		})
		/*    获取验证码结束*/
	});
var validCode=true;
function timedCount () {
	var time=60	;
	var code=$("#getCode");
	if (validCode) {
		validCode=false;
		code.addClass("msgs1");
		var t=setInterval(function  () {
			time--;
			code.html(time+"秒");
			if (time==0) {
				clearInterval(t);
				code.html("重新获取");
				validCode=true;
				code.removeClass("msgs1");
			}
		},1000)
	}
}
</script>
</html>
